/** \file
* WIN32-specific implementation of the Timer class.
* This file is part of Chorus, available at
* http://code.google.com/p/chorus-twitter/ . This file and all associated files
* and derivative works are bound by the terms of the LGPL 3.0 license,
* available at http://www.gnu.org/licenses/lgpl-3.0-standalone.html .
* \par Subversion URL:
* \$URL: http://chorus-twitter.googlecode.com/svn/branches/cpp/src/system/win32/Timer.cpp $
* \version \$Rev: 153 $
* \date    \$Date: 2010-04-06 07:43:42 +0000 (Tue, 06 Apr 2010) $
*/

#define NEEDS_WIN32
#include "config.h"

#include <iostream>

#include "system/Timer.hpp"

using namespace std;

Timer::Timer()
{
	if (!QueryPerformanceCounter(&time0))
	{
		cerr << "QueryPerformanceCounter failed, error" << GetLastError()
			<< '\n';
		return;
	}
	if (!QueryPerformanceFrequency(&freq))
	{
		cerr << "QueryPerformanceFrequency failed, error" << GetLastError()
			<< '\n';
		return;
	}
}

long double Timer::getTimeDouble() const
{
	LARGE_INTEGER time1;
	if (!QueryPerformanceCounter(&time1))
	{
		cerr << "QueryPerformanceCounter failed, error" << GetLastError()
			<< '\n';
		return 0;
	}
	return ((long double)(time1.QuadPart - time0.QuadPart))/freq.QuadPart;
}
